package com.apes.scm.masterdata.product.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * @program: apes-server
 * @description: 常用商品
 * @author: czs
 * @create: 2022-07-01 10:59
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = StarProduct.CONST_TABLE_NAME, indexes = {
        @Index(columnList = "star_person"),
        @Index(columnList = "product_id,star_person", unique = true)
})
public class StarProduct extends Model {
    public static final String CONST_TABLE_NAME = "star_product";

    @Id
    @Column(name = "id", length = 10)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "常用商品明细编码", padding = 10)
    @Comment("常用商品明细编码")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "id")
    @Comment("商品")
    private Product product;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "star_person", referencedColumnName = "id")
    @Comment("收藏人员")
    private PartyRole starPerson;

    @Column(name = "use_number", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("使用次数")
    private double useNumber = 0;

    @Column(name = "valid", nullable = false, columnDefinition = "number(1,0) default 1")
    @Comment("有效标记")
    private boolean valid = true;

}
